﻿@model CollectDTO[]
@{
                /**/

                ViewBag.Title = "商品收藏";
                Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote collect_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal collectAdd_btn">添加收藏</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后未提交的数据不会自动保存</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold">@Model.Count() </span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form collect_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>

                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>收藏人</th>
                            <th>收藏商品</th>
                            <th>添加该商品到收藏的时间</th>
                            <th>是否还在收藏</th>

                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="collect_content">
                        @foreach (var collect in Model)
                        {
                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                                </td>
                                <th>@collect.UserName</th>
                                <th>@collect.GoodName</th>
                                <th>@collect.CreateDateTime</th>
                                <th>@collect.IsExist</th>

                                <td>
                                    <a class="layui-btn layui-btn-mini collect_edit"><i class="iconfont icon-edit"></i> 编辑</a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini collect_del" data-id="@collect.Id">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>
                        }


                    </tbody>
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page"></div>
                </div>
            </div>

        </div>
    </div>

</section>

@section FooterScript{
    <script type="text/javascript">

        var $;

        var appConfig = {
            name: "collect",    //需要和页面名称对应
            title: "收藏商品",    //显示的名称
            addUrl: "/Collect/AddNew",   //添加弹框的路径
            editUrl: "/Collect/Edit",      //修改弹框的路径
            $: "",
            layer: "",

            //批量删除Ajax
            batchDel: function (data) {     //Array data 得到的是 需要删除的id
                $ = appConfig.$

                $.ajax({
                    url: "/Collect/BatchDel",
                    method: "post",
                    dataType: "json",
                    data: { "collectIds": data },    //$(data)要删除的数组
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", {
                                icon: 1, time: 1000, end: function () {
                                    location.reload();
                                }
                            });



                        } else {
                            appConfig.layer.msg("删除失败", {
                                icon: 5, time: 1000, end: function () {
                                    location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        appConfig.layer.msg("删除失败", {
                            icon: 5, time: 2000, end: function () {
                                location.reload();
                            }
                        });

                        location.reload();
                    }
                });


                //todo:在此处添加批量删除记录的ajax



            },

            del: function (data) {
                $ = appConfig.$

                $.ajax({
                    url: "/Collect/Delete/",
                    method: "post",
                    dataType: "json",
                    data: { "collectId": data },
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", { icon: 1 });

                        } else {
                            appConfig.layer.msg("删除失败", { icon: 5 });
                        }
                    },
                    error: function () {
                        appConfig.layer.msg("删除失败", { icon: 5 });
                    }
                });

                //todo:在此处添加删除记录的ajax
            }
        };

    </script>
}

